package cn.edu.nju.software.cdiy.algorithm.assessor;

import cn.edu.nju.software.cdiy.bean.HardwareSet;
import cn.edu.nju.software.cdiy.service.UtilService;

public class ApplicationScopeAssessor implements Assessor<ApplicationScopeMessager> {
	
	private UtilService utilService;
	
	public void setUtilService(UtilService utilService) {
		this.utilService = utilService;
	}

	@Override
	public ApplicationScopeMessager generateAssess(HardwareSet hardwareSet) {
		
		// 待返回的messager
		ApplicationScopeMessager asm = new ApplicationScopeMessager();
		HardwareSet hs = utilService.fillHardwareSet(hardwareSet);
		gameAssess(hs, asm);
		designAssess(hs, asm);
		businessAssess(hs, asm);
		homeAssess(hs, asm);

		return asm;
	}

	private void businessAssess(HardwareSet hs, ApplicationScopeMessager asm) {
		// 对hs进行分析，若关于商务的部件还不存在于hs中，则直接return
		String busmes = "商务性能评估：";
		
		if (hs.getCpu() != null) {
			// 判断cpu的核心数量（双核以上）和制作工艺（45nm以上）为合适
			if (hs.getCpu().getManuTech().getKey() == 173
					&& hs.getCpu().getCoreNum().getKey() >= 922) {
				busmes = busmes + "cpu适合，";
			} else if (hs.getCpu().getManuTech().getKey() < 173
					&& hs.getCpu().getCoreNum().getKey() >= 922) {
				busmes = busmes + "cpu非常适合，";
			} else
				busmes = busmes + "cpu不适合，";
		} else
			busmes = busmes + "请选择CPU，";
		
		if (hs.getMemory() != null) {
			// 判断内存的容量（2G以上）和内存类型（DDR3）为合适
			if (hs.getMemory().getMemCapacity().getKey() == 268
					&& hs.getMemory().getMemType().getKey() == 233) {
				busmes = busmes + "内存适合；";
			} else if (hs.getMemory().getMemCapacity().getKey() < 268
					&& hs.getMemory().getMemType().getKey() == 233) {
				busmes = busmes + "内存非常适合；";
			} else
				busmes = busmes + "内存不适合；";
		} else
			busmes = busmes + "请选择内存；";

		asm.setBusinessMessage(busmes);
	}

	private void designAssess(HardwareSet hs, ApplicationScopeMessager asm) {
		// 对hs进行分析，若关于设计的部件还不存在于hs中，则直接return
		String desmes = "设计性能评估：";
		if (hs.getCpu() != null) {
			// 判断cpu的核心数量（四核以上）和制作工艺（32nm以上）为合适
			if (hs.getCpu().getCoreNum().getKey() >= 924
					&& hs.getCpu().getManuTech().getKey() <= 172) {
				desmes = desmes + "cpu非常适合，";
			} else
				desmes = desmes + "cpu不适合，";
		} else
			desmes = desmes + "请选择CPU，";
		if (hs.getMemory() != null) {
			// 判断内存的容量（4G以上）和内存类型（DDR3）为合适
			if (hs.getMemory().getMemCapacity().getKey() > 267
					&& hs.getMemory().getMemType().getKey() == 233) {
				desmes = desmes + "内存非常适合";
			} else if (hs.getMemory().getMemCapacity().getKey() == 267
					&& hs.getMemory().getMemType().getKey() == 233) {
				desmes = desmes + "内存适合，";
			} else
				desmes = desmes + "内存不适合，";
		} else
			desmes = desmes + "请选择内存，";
		if (hs.getGraphics() != null) {
			// 判断显卡的显存（1GB以上），显存类型（GDDR5）和显存核心位宽（256bit以上）为合适
			if (hs.getGraphics().getVideoMemCapacity().getKey() >= 420
					&& hs.getGraphics().getVideoMemType().getKey() == 406
					&& hs.getGraphics().getVideoMemBitWide().getKey() == 436) {
				desmes = desmes + "显卡适合；";
			} else
				desmes = desmes + "显卡不适合；";
		} else
			desmes = desmes + "请选择显卡；";

		asm.setDesignMessage(desmes);
	}

	private void gameAssess(HardwareSet hs, ApplicationScopeMessager asm) {
		// 对hs进行分析，若关于的游戏还不存在于hs中，则直接return
		String gammes = "游戏性能评估："; 
		if (hs.getCpu() != null) {
			// 判断cpu的核心数量（双核以上）和制作工艺（32nm以上）为合适
			if (hs.getCpu().getManuTech().getKey() == 172
					&& hs.getCpu().getCoreNum().getKey() >= 922) {
				gammes = gammes + "cpu适合，";
			} else if (hs.getCpu().getManuTech().getKey() < 172
					&& hs.getCpu().getCoreNum().getKey() >= 922) {
				gammes = gammes + "cpu非常适合，";
			} else
				gammes = gammes + "cpu不适合，";
		} else
			gammes = gammes + "请选择CPU，";
		
		if (hs.getMemory() != null) {
			// 判断内存的容量（4G以上）和内存类型（DDR3）为合适
			if (hs.getMemory().getMemCapacity().getKey() > 267
					&& hs.getMemory().getMemType().getKey() == 233) {
				gammes = gammes + "内存非常适合，";
			} else if (hs.getMemory().getMemCapacity().getKey() == 267
					&& hs.getMemory().getMemType().getKey() == 233) {
				gammes = gammes + "内存适合，";
			} else
				gammes = gammes + "内存不适合，";
		} else
			gammes = gammes + "请选择内存";

		if (hs.getGraphics() != null) {
			// 判断显卡的显存（1GB以上），显存类型（GDDR5），显存核心位宽（256bit以上）和显卡芯片制作工艺（40nm以上）为合适
			if (hs.getGraphics().getVideoMemCapacity().getKey() >= 420
					&& hs.getGraphics().getVideoMemType().getKey() == 406
					&& hs.getGraphics().getVideoMemBitWide().getKey() == 436
					&& hs.getGraphics().getManuTech().getKey() == 381) {
				gammes = gammes + "显卡非常适合；";
			} else
				gammes = gammes + "显卡不适合；";

		} else
			gammes = gammes + "请选择显卡";

		asm.setGameMessage(gammes);
	}

	private void homeAssess(HardwareSet hs, ApplicationScopeMessager asm) {
		// 对hs进行分析，若关于的家用还不存在于hs中，则直接return
		String hommes = "家用性能评估：";
		if (hs.getCpu() != null) {
			// 判断cpu的核心数量（双核以上）和制作工艺（32nm以上）为合适
			if (hs.getCpu().getManuTech().getKey() == 172
					&& hs.getCpu().getCoreNum().getKey() >= 922) {
				hommes = hommes + "cpu适合，";
			} else if (hs.getCpu().getManuTech().getKey() < 172
					&& hs.getCpu().getCoreNum().getKey() >= 922) {
				hommes = hommes + "cpu非常适合，";
			} else
				hommes = hommes + "cpu不适合，";
		} else
			hommes = hommes + "请选择CPU，";
		
		if (hs.getMemory() != null) {
			// 判断内存的容量（2G以上）和内存类型（DDR3）为合适
			if (hs.getMemory().getMemCapacity().getKey() == 268
					&& hs.getMemory().getMemType().getKey() == 233) {
				hommes = hommes + "内存适合；";
			} else if (hs.getMemory().getMemCapacity().getKey() < 268
					&& hs.getMemory().getMemType().getKey() == 233) {
				hommes = hommes + "内存非常适合；";
			} else
				hommes = hommes + "内存不适合；";
		} else
			hommes = hommes + "请选择内存；";

		asm.setHomeMessage(hommes);
	}

}
